﻿#pragma once

#include "Math/IntPoint.h"
#include "Containers/Delegate.h"
#include "Input/Keys.h"
#include "Event/MouseEvent.h"
#include "Event/KeyboardEvent.h"
#include "Scene/SceneNodeComponent.h"

#include "InputComponent.m.h"

class RViewportWidget;

RCLASS(ExtraHeader="Widgets/ViewportWidget.h")
class WHENGINE_API RInputComponent: public RSceneNodeComponent
{
    ROBJECT
public:

    virtual void OnBeginPlay() override;
    virtual void OnEndPlay() override;

public:
    //返回是否可以接受来自指定视口的输入，如果返回true，则视口的输入将被传递给此组件
    //如果不绑定此事件，则默认允许接受来自任何视口的输入
    TDelegate<bool,TSharedObjectPtr<RViewportWidget>> CanAccept;

    TDelegate<void> OnLeftMouseButtonPressed;
    TDelegate<void> OnRightMouseButtonPressed;
    TDelegate<void> OnWheelPressed;

    TDelegate<void> OnLeftMouseButtonReleased;
    TDelegate<void> OnRightMouseButtonReleased;
    TDelegate<void> OnWheelReleased;

    TDelegate<void,const SIntPoint & /*Delta*/ > OnMouseMoved;

    //for bind keys in callback awy
    TMap<EKey, TDelegate<void>> OnKeyPressedEvents;
    TMap<EKey, TDelegate<void>> OnKeyReleasedEvents;

    //for bind keys in override way
    RFUNCTION()
    virtual void OnKeyPressed(EKey InKey) {}
    RFUNCTION()
    virtual void OnKeyReleased(EKey InKey) {}

    bool OnViewportMouseButtonPressed(const SMouseButtonEvent& InMouseEvent);
    bool OnViewportMouseButtonReleased(const SMouseButtonEvent& InMouseEvent);
    bool OnViewportMouseMoved(const SMouseButtonEvent& InMouseEvent);

    bool ProcessKeyboardEvent(const SKeyboardEvent& BoardkeyEvent); 

};